//
//  ParserClass.m
//  iRMAP
//
//  Created by Ryan Enguero on 4/8/14.
//  Copyright (c) 2014 engueroryan. All rights reserved.
//

#import "ParserClass.h"
#import "User.h"
#import "Company.h"
#import "Devices.h"
#import "DevicesCurrentTemperature-PGS.h"
#import "DevicesCurrentTemperature-Platinum.h"
#import "DevicesCurrentTemperature-CO2Incubator.h"
#import "DevicesCurrentTemperature-EGS-G2.h"
#import "DevicesCurrentTemperature-OFA_IFA_IFC_INA.h"
#import "ViewLogs.h"
#import "UserNotified.h"

static ParserClass *sharedItem = nil;

@implementation ParserClass

#pragma mark - User Details

- (NSArray*)userdetails{
    
    return user;
}

- (void)userDetails:(NSDictionary*)details{
    
    NSLog(@"Details = %@", details);
    
    user = [NSMutableArray array];
    
    User *userDetails = [User userWithUserID:[NSString stringWithFormat:@"%@",[[[details objectForKey:@"return"] objectForKey:@"user"] objectForKey:@"id"]]
                           andSessionTimeOut:[NSString stringWithFormat:@"%@",[[details objectForKey:@"return"] objectForKey:@"sessionTimeoutSeconds"]]
                                andSessionID:[NSString stringWithFormat:@"%@",[[details objectForKey:@"return"] objectForKey:@"sessionid"]]
                                andFirstName:[NSString stringWithFormat:@"%@",[[[details objectForKey:@"return"] objectForKey:@"user"] objectForKey:@"firstName"]]
                                 andLastName:[NSString stringWithFormat:@"%@",[[[details objectForKey:@"return"] objectForKey:@"user"] objectForKey:@"lastName"]]
                                     andRole:[NSString stringWithFormat:@"%@",[[[details objectForKey:@"return"] objectForKey:@"user"] objectForKey:@"role"]]
                                    andEmail:[NSString stringWithFormat:@"%@",[[[details objectForKey:@"return"] objectForKey:@"user"] objectForKey:@"email"]]
                                    andPhone:[NSString stringWithFormat:@"%@",[[[details objectForKey:@"return"] objectForKey:@"user"] objectForKey:@"phone"]]];
    
    [user addObject:userDetails];
    
}

#pragma mark - Company

- (NSArray*)companyDetails{

    return companies;
}

- (void)listOfCompanies:(NSDictionary*)companyDetails{

    NSLog(@"Companies = %@", companyDetails);
    
    companies = [NSMutableArray array];
    
    for (int i = 0; i < [[[companyDetails objectForKey:@"response"] objectForKey:@"companies"] count]; i++) {
    
    Company *company = [Company companyWithDomainID:[NSString stringWithFormat:@"%@", [[[[companyDetails objectForKey:@"response"] objectForKey:@"companies"] objectAtIndex:i] objectForKey:@"domainId"]]
                                       andCompanyID:[NSString stringWithFormat:@"%@", [[[[companyDetails objectForKey:@"response"] objectForKey:@"companies"] objectAtIndex:i] objectForKey:@"companyId"]]
                                     andCompanyName:[NSString stringWithFormat:@"%@", [[[[companyDetails objectForKey:@"response"] objectForKey:@"companies"] objectAtIndex:i] objectForKey:@"companyName"]]
                                     andContactName:[NSString stringWithFormat:@"%@", [[[[companyDetails objectForKey:@"response"] objectForKey:@"companies"] objectAtIndex:i] objectForKey:@"contactName"]]
                                    andContactEmail:[NSString stringWithFormat:@"%@", [[[[companyDetails objectForKey:@"response"] objectForKey:@"companies"] objectAtIndex:i] objectForKey:@"contactEmail"]]
                                andContactCellPhone:[NSString stringWithFormat:@"%@", [[[[companyDetails objectForKey:@"response"] objectForKey:@"companies"] objectAtIndex:i] objectForKey:@"contactCellPhone"]]
                                  andCompanyAddress:[NSString stringWithFormat:@"%@", [[[[companyDetails objectForKey:@"response"] objectForKey:@"companies"] objectAtIndex:i] objectForKey:@"companyAddress"]]
                                          andZoneID:[NSString stringWithFormat:@"%@", [[[[companyDetails objectForKey:@"response"] objectForKey:@"companies"] objectAtIndex:i] objectForKey:@"zoneId"]]
                                     andAmcDateFrom:[NSString stringWithFormat:@"%@", [[[[companyDetails objectForKey:@"response"] objectForKey:@"companies"] objectAtIndex:i] objectForKey:@"amcDateFrom"]]
                                       andAmcDateTo:[NSString stringWithFormat:@"%@", [[[[companyDetails objectForKey:@"response"] objectForKey:@"companies"] objectAtIndex:i] objectForKey:@"amcDateTo"]]];
    
    
    [companies addObject:company];
        
    }
}

#pragma mark - Devices

- (NSArray*)deviceDetails{
    
    return devices;
}

- (void)listOfDevices:(NSDictionary*)deviceDetails{
    
    NSLog(@"Devices = %@", deviceDetails);
    
    devices = [NSMutableArray array];
    
    
    NSPredicate *predicateGoldSilverPlatinum = [NSPredicate predicateWithFormat:@"deviceType = %@ || deviceType = %@", @"ultf_silver",@"ultf_gold"];
    NSArray *resultGoldSilverPlatinum = [[[deviceDetails objectForKey:@"response"] objectForKey:@"devices"] filteredArrayUsingPredicate:predicateGoldSilverPlatinum];
   // resultGoldSilverPlatinum = [[resultGoldSilverPlatinum reverseObjectEnumerator] allObjects];
    NSLog(@"ResultGoldSilver = %@", resultGoldSilverPlatinum);
    
    
    NSPredicate *predicatePlatinum = [NSPredicate predicateWithFormat:@"deviceType = %@", @"ultf_platinum"];
    
    NSArray *resultPlatinum = [[[deviceDetails objectForKey:@"response"] objectForKey:@"devices"] filteredArrayUsingPredicate:predicatePlatinum];
   // resultPlatinum = [[resultPlatinum reverseObjectEnumerator] allObjects];
    NSLog(@"ResultPlatinum = %@", resultPlatinum);
    

    NSPredicate *predicateIncubator = [NSPredicate predicateWithFormat:@"deviceType = %@", @"co2_incubator"];
    NSArray *resultIncubator = [[[deviceDetails objectForKey:@"response"] objectForKey:@"devices"] filteredArrayUsingPredicate:predicateIncubator];
    //resultIncubator = [[resultIncubator reverseObjectEnumerator] allObjects];
    NSLog(@"ResultIncubator = %@", resultIncubator);
    
    NSPredicate *predicateEcsG2 = [NSPredicate predicateWithFormat:@"deviceType = %@", @"ecs-g2"];
    NSArray *resultEcsG2 = [[[deviceDetails objectForKey:@"response"] objectForKey:@"devices"] filteredArrayUsingPredicate:predicateEcsG2];
//    resultEcsG2 = [[resultEcsG2 reverseObjectEnumerator] allObjects];
    NSLog(@"ResultEcsG2 = %@", resultEcsG2);
    
    NSPredicate *predicateOFAIFAIFCINA = [NSPredicate predicateWithFormat:@"deviceType = %@ || deviceType = %@ || deviceType = %@ || deviceType = %@", @"ofa",@"ifa", @"ifc", @"ina"];
    NSArray *resultOFAIFAIFCINA = [[[deviceDetails objectForKey:@"response"] objectForKey:@"devices"] filteredArrayUsingPredicate:predicateOFAIFAIFCINA];
  //  resultOFAIFAIFCINA = [[resultOFAIFAIFCINA reverseObjectEnumerator] allObjects];
    NSLog(@"ResultOFAIFAIFCINA = %@", resultOFAIFAIFCINA);
    
    for (int i = 0; i < [resultGoldSilverPlatinum count]; i++) {
        
        Devices *deviceGoldSilverPlatinum = [DevicesCurrentTemperature_PGS devicesWithFreezerID:[NSString stringWithFormat:@"%@",[[resultGoldSilverPlatinum objectAtIndex:i] objectForKey:@"freezerId"]]
                                                                                 andUID:[NSString stringWithFormat:@"%@",[[resultGoldSilverPlatinum objectAtIndex:i] objectForKey:@"UID"]]
                                                                          andDeviceName:[NSString stringWithFormat:@"%@",[[resultGoldSilverPlatinum objectAtIndex:i] objectForKey:@"deviceName"]]
                                                                           andCompanyId:[NSString stringWithFormat:@"%@",[[resultGoldSilverPlatinum objectAtIndex:i] objectForKey:@"companyId"]]
                                                                       andMeasureStatus:[NSString stringWithFormat:@"%@",[[resultGoldSilverPlatinum objectAtIndex:i] objectForKey:@"measureStatus"]]
                                                                         andMeasureName:[NSString stringWithFormat:@"%@",[[resultGoldSilverPlatinum objectAtIndex:i] objectForKey:@"measureName"]]
                                                                  andMeasureDescription:[NSString stringWithFormat:@"%@",[[resultGoldSilverPlatinum objectAtIndex:i] objectForKey:@"measureDecription"]]
                                                                     andMeasureSeverity:[NSString stringWithFormat:@"%@",[[resultGoldSilverPlatinum objectAtIndex:i] objectForKey:@"measureSeverity"]]
                                                                    andHealthStatusCode:[NSString stringWithFormat:@"%@",[[resultGoldSilverPlatinum objectAtIndex:i] objectForKey:@"healthStatusCode"]]
                                                                    andHealthStatusText:[NSString stringWithFormat:@"%@",[[resultGoldSilverPlatinum objectAtIndex:i] objectForKey:@"healthStatusText"]]
                                                                   andHealthStatusColor:[NSString stringWithFormat:@"%@",[[resultGoldSilverPlatinum objectAtIndex:i] objectForKey:@"healthStatusColor"]]
                                                                     andConnectionState:[NSString stringWithFormat:@"%@",[[[resultGoldSilverPlatinum objectAtIndex:i] objectForKey:@"connecttionState"] objectForKey:@"status"]]
                                                            andChamberTemperatureSensor:[NSString stringWithFormat:@"%@",[[[resultGoldSilverPlatinum objectAtIndex:i] objectForKey:@"currentTemperature"] objectForKey:@"chamberTemperatureSensor"]]
                                                                     andChamberSetPoint:[NSString stringWithFormat:@"%@",[[[resultGoldSilverPlatinum objectAtIndex:i] objectForKey:@"currentTemperature"] objectForKey:@"chamberSetPoint"]]andDeviceType:[NSString stringWithFormat:@"%@",[[resultGoldSilverPlatinum objectAtIndex:i] objectForKey:@"deviceType"]]];
        
        [devices addObject:deviceGoldSilverPlatinum];
    
    }
    
    
    for (int i = 0; i < [resultPlatinum count]; i++) {
        
        Devices *devicePlatinum = [DevicesCurrentTemperature_Platinum devicesWithFreezerID:[NSString stringWithFormat:@"%@",[[resultPlatinum objectAtIndex:i] objectForKey:@"freezerId"]]
                                                                                         andUID:[NSString stringWithFormat:@"%@",[[resultPlatinum objectAtIndex:i] objectForKey:@"UID"]]
                                                                                  andDeviceName:[NSString stringWithFormat:@"%@",[[resultPlatinum objectAtIndex:i] objectForKey:@"deviceName"]]
                                                                                   andCompanyId:[NSString stringWithFormat:@"%@",[[resultPlatinum objectAtIndex:i] objectForKey:@"companyId"]]
                                                                               andMeasureStatus:[NSString stringWithFormat:@"%@",[[resultPlatinum objectAtIndex:i] objectForKey:@"measureStatus"]]
                                                                                 andMeasureName:[NSString stringWithFormat:@"%@",[[resultPlatinum objectAtIndex:i] objectForKey:@"measureName"]]
                                                                          andMeasureDescription:[NSString stringWithFormat:@"%@",[[resultPlatinum objectAtIndex:i] objectForKey:@"measureDecription"]]
                                                                             andMeasureSeverity:[NSString stringWithFormat:@"%@",[[resultPlatinum objectAtIndex:i] objectForKey:@"measureSeverity"]]
                                                                            andHealthStatusCode:[NSString stringWithFormat:@"%@",[[resultPlatinum objectAtIndex:i] objectForKey:@"healthStatusCode"]]
                                                                            andHealthStatusText:[NSString stringWithFormat:@"%@",[[resultPlatinum objectAtIndex:i] objectForKey:@"healthStatusText"]]
                                                                           andHealthStatusColor:[NSString stringWithFormat:@"%@",[[resultPlatinum objectAtIndex:i] objectForKey:@"healthStatusColor"]]
                                                                             andConnectionState:[NSString stringWithFormat:@"%@",[[[resultPlatinum objectAtIndex:i] objectForKey:@"connecttionState"] objectForKey:@"status"]]
                                                                    andChamberTemperatureSensor:[NSString stringWithFormat:@"%@",[[[resultPlatinum objectAtIndex:i] objectForKey:@"currentTemperature"] objectForKey:@"chamberTemperatureSensor"]]
                                                                             andChamberSetPoint:[NSString stringWithFormat:@"%@",[[[resultPlatinum objectAtIndex:i] objectForKey:@"currentTemperature"] objectForKey:@"chamberSetPoint"]] andDeviceType:[[resultPlatinum objectAtIndex:i] objectForKey:@"deviceType"]];
        
       
        
        [devices addObject:devicePlatinum];
        
    }
    
    for (int i = 0; i < [resultIncubator count]; i++) {
        
        Devices *devicesIncubator = [DevicesCurrentTemperature_CO2Incubator devicesWithFreezerID:[NSString stringWithFormat:@"%@",[[resultIncubator objectAtIndex:i] objectForKey:@"freezerId"]]
                                                                                          andUID:[NSString stringWithFormat:@"%@",[[resultIncubator objectAtIndex:i] objectForKey:@"UID"]]
                                                                                   andDeviceName:[NSString stringWithFormat:@"%@",[[resultIncubator objectAtIndex:i] objectForKey:@"deviceName"]]
                                                                                    andCompanyId:[NSString stringWithFormat:@"%@",[[resultIncubator objectAtIndex:i] objectForKey:@"companyId"]]
                                                                                andMeasureStatus:[NSString stringWithFormat:@"%@",[[resultIncubator objectAtIndex:i] objectForKey:@"measureStatus"]]
                                                                                  andMeasureName:[NSString stringWithFormat:@"%@",[[resultIncubator objectAtIndex:i] objectForKey:@"measureName"]]
                                                                           andMeasureDescription:[NSString stringWithFormat:@"%@",[[resultIncubator objectAtIndex:i] objectForKey:@"measureDecription"]]
                                                                              andMeasureSeverity:[NSString stringWithFormat:@"%@",[[resultIncubator objectAtIndex:i] objectForKey:@"measureSeverity"]]
                                                                             andHealthStatusCode:[NSString stringWithFormat:@"%@",[[resultIncubator objectAtIndex:i] objectForKey:@"healthStatusCode"]]
                                                                             andHealthStatusText:[NSString stringWithFormat:@"%@",[[resultIncubator objectAtIndex:i] objectForKey:@"healthStatusText"]]
                                                                            andHealthStatusColor:[NSString stringWithFormat:@"%@",[[resultIncubator objectAtIndex:i] objectForKey:@"healthStatusColor"]]
                                                                              andConnectionState:[NSString stringWithFormat:@"%@",[[[resultIncubator objectAtIndex:i] objectForKey:@"connecttionState"] objectForKey:@"status"]]
                                                                          andTemperatureSetPoint:[NSString stringWithFormat:@"%@",[[[resultIncubator objectAtIndex:i] objectForKey:@"currentTemperature"] objectForKey:@"temperatureSetPoint"]]
                                                                                  andCo2SetPoint:[NSString stringWithFormat:@"%@",[[[resultIncubator objectAtIndex:i] objectForKey:@"currentTemperature"] objectForKey:@"co2SetPoint"]]
                                                                                   andO2SetPoint:[NSString stringWithFormat:@"%@",[[[resultIncubator objectAtIndex:i] objectForKey:@"currentTemperature"] objectForKey:@"o2SetPoint"]]
                                                                         andTemperatureSensorStr:[NSString stringWithFormat:@"%@",[[[resultIncubator objectAtIndex:i] objectForKey:@"currentTemperature"] objectForKey:@"temperatureSensor"]]
                                                                                    andCo2Sensor:[NSString stringWithFormat:@"%@",[[[resultIncubator objectAtIndex:i] objectForKey:@"currentTemperature"] objectForKey:@"co2Sensor"]]
                                                                                     andO2Sensor:[NSString stringWithFormat:@"%@",[[[resultIncubator objectAtIndex:i] objectForKey:@"currentTemperature"] objectForKey:@"o2Sensor"]]
                                                                                     andRhSensor:[NSString stringWithFormat:@"%@",[[[resultIncubator objectAtIndex:i] objectForKey:@"currentTemperature"] objectForKey:@"rhSensor"]]andDeviceType:[NSString stringWithFormat:@"%@",[[resultIncubator objectAtIndex:i] objectForKey:@"deviceType"]]];
        
        [devices addObject:devicesIncubator];
        
    }
    
    
    for (int i = 0; i < [resultEcsG2 count]; i++) {
        
        Devices *devicesEGs = [DevicesCurrentTemperature_EGS_G2  devicesWithFreezerID:[NSString stringWithFormat:@"%@",[[resultEcsG2 objectAtIndex:i] objectForKey:@"freezerId"]]
                                                                                                        andUID:[NSString stringWithFormat:@"%@",[[resultEcsG2 objectAtIndex:i] objectForKey:@"UID"]]
                                                                                                 andDeviceName:[NSString stringWithFormat:@"%@",[[resultEcsG2 objectAtIndex:i] objectForKey:@"deviceName"]]
                                                                                                  andCompanyId:[NSString stringWithFormat:@"%@",[[resultEcsG2 objectAtIndex:i] objectForKey:@"companyId"]]
                                                                                              andMeasureStatus:[NSString stringWithFormat:@"%@",[[resultEcsG2 objectAtIndex:i] objectForKey:@"measureStatus"]]
                                                                                                andMeasureName:[NSString stringWithFormat:@"%@",[[resultEcsG2 objectAtIndex:i] objectForKey:@"measureName"]]
                                                                                         andMeasureDescription:[NSString stringWithFormat:@"%@",[[resultEcsG2 objectAtIndex:i] objectForKey:@"measureDecription"]]
                                                                                            andMeasureSeverity:[NSString stringWithFormat:@"%@",[[resultEcsG2 objectAtIndex:i] objectForKey:@"measureSeverity"]]
                                                                                           andHealthStatusCode:[NSString stringWithFormat:@"%@",[[resultEcsG2 objectAtIndex:i] objectForKey:@"healthStatusCode"]]
                                                                                           andHealthStatusText:[NSString stringWithFormat:@"%@",[[resultEcsG2 objectAtIndex:i] objectForKey:@"healthStatusText"]]
                                                                                          andHealthStatusColor:[NSString stringWithFormat:@"%@",[[resultEcsG2 objectAtIndex:i] objectForKey:@"healthStatusColor"]]
                                                                                            andConnectionState:[NSString stringWithFormat:@"%@",[[[resultEcsG2 objectAtIndex:i] objectForKey:@"connecttionState"] objectForKey:@"status"]]
                                                                                   andInFlowSensor:[NSString stringWithFormat:@"%@",[[[resultEcsG2 objectAtIndex:i] objectForKey:@"currentTemperature"] objectForKey:@"inFlowSensor"]]
                                                                                            andDownFlowSensor:[NSString stringWithFormat:@"%@",[[[resultEcsG2 objectAtIndex:i] objectForKey:@"currentTemperature"] objectForKey:@"downFlowSensor"]] andDeviceType:[NSString stringWithFormat:@"%@",[[resultEcsG2 objectAtIndex:i] objectForKey:@"deviceType"]]];
                                                        
                                                        
        [devices addObject:devicesEGs];
    }
    
    for (int i = 0; i < [resultOFAIFAIFCINA count]; i++) {
        
        Devices *devicesOFAIFAIFCINA = [DevicesCurrentTemperature_OFA_IFA_IFC_INA devicesWithFreezerID:[NSString stringWithFormat:@"%@",[[resultOFAIFAIFCINA objectAtIndex:i] objectForKey:@"freezerId"]]
                                                                                                andUID:[NSString stringWithFormat:@"%@",[[resultOFAIFAIFCINA objectAtIndex:i] objectForKey:@"UID"]]
                                                                                         andDeviceName:[NSString stringWithFormat:@"%@",[[resultOFAIFAIFCINA objectAtIndex:i] objectForKey:@"deviceName"]]
                                                                                          andCompanyId:[NSString stringWithFormat:@"%@",[[resultOFAIFAIFCINA objectAtIndex:i] objectForKey:@"companyId"]]
                                                                                      andMeasureStatus:[NSString stringWithFormat:@"%@",[[resultOFAIFAIFCINA objectAtIndex:i] objectForKey:@"measureStatus"]]
                                                                                        andMeasureName:[NSString stringWithFormat:@"%@",[[resultOFAIFAIFCINA objectAtIndex:i] objectForKey:@"measureName"]]
                                                                                 andMeasureDescription:[NSString stringWithFormat:@"%@",[[resultOFAIFAIFCINA objectAtIndex:i] objectForKey:@"measureDecription"]]
                                                                                    andMeasureSeverity:[NSString stringWithFormat:@"%@",[[resultOFAIFAIFCINA objectAtIndex:i] objectForKey:@"measureSeverity"]]
                                                                                   andHealthStatusCode:[NSString stringWithFormat:@"%@",[[resultOFAIFAIFCINA objectAtIndex:i] objectForKey:@"healthStatusCode"]]
                                                                                   andHealthStatusText:[NSString stringWithFormat:@"%@",[[resultOFAIFAIFCINA objectAtIndex:i] objectForKey:@"healthStatusText"]]
                                                                                  andHealthStatusColor:[NSString stringWithFormat:@"%@",[[resultOFAIFAIFCINA objectAtIndex:i] objectForKey:@"healthStatusColor"]]
                                                                                    andConnectionState:[NSString stringWithFormat:@"%@",[[[resultOFAIFAIFCINA objectAtIndex:i] objectForKey:@"connecttionState"] objectForKey:@"status"]]
                                                                           andChamberTemperatureSensor:[NSString stringWithFormat:@"%@",[[[resultOFAIFAIFCINA objectAtIndex:i] objectForKey:@"currentTemperature"] objectForKey:@"chamberTemperatureSensor"]]
                                                                                    andChamberSetPoint:[NSString stringWithFormat:@"%@",[[[resultOFAIFAIFCINA objectAtIndex:i] objectForKey:@"currentTemperature"] objectForKey:@"chamberSetPoint"]] andDeviceType:[NSString stringWithFormat:@"%@",[[resultOFAIFAIFCINA objectAtIndex:i] objectForKey:@"deviceType"]]];
    
    
        [devices addObject:devicesOFAIFAIFCINA];
    }
    
    
    
    NSLog(@"Final Result = %@", devices);
    
//    for (int i = 0; i < [[[deviceDetails objectForKey:@"response"] objectForKey:@"devices"] count]; i++) {
//        
//        Devices *device = [Devices devicesWithFreezerID:[NSString stringWithFormat:@"%@",[[[[deviceDetails objectForKey:@"response"] objectForKey:@"devices"] objectAtIndex:i]objectForKey:@"freezerId"]]
//                                                 andUID:[NSString stringWithFormat:@"%@",[[[[deviceDetails objectForKey:@"response"] objectForKey:@"devices"] objectAtIndex:i]objectForKey:@"UID"]]
//                                          andDeviceName:[NSString stringWithFormat:@"%@",[[[[deviceDetails objectForKey:@"response"] objectForKey:@"devices"] objectAtIndex:i]objectForKey:@"deviceName"]]
//                                           andCompanyId:[NSString stringWithFormat:@"%@",[[[[deviceDetails objectForKey:@"response"] objectForKey:@"devices"] objectAtIndex:i]objectForKey:@"companyId"]]
//                                       andMeasureStatus:[NSString stringWithFormat:@"%@",[[[[deviceDetails objectForKey:@"response"] objectForKey:@"devices"] objectAtIndex:i]objectForKey:@"measureStatus"]]
//                                         andMeasureName:[NSString stringWithFormat:@"%@",[[[[deviceDetails objectForKey:@"response"] objectForKey:@"devices"] objectAtIndex:i]objectForKey:@"measureName"]]
//                                  andMeasureDescription:[NSString stringWithFormat:@"%@",[[[[deviceDetails objectForKey:@"response"] objectForKey:@"devices"] objectAtIndex:i]objectForKey:@"measureDescription"]]
//                                     andMeasureSeverity:[NSString stringWithFormat:@"%@",[[[[deviceDetails objectForKey:@"response"] objectForKey:@"devices"] objectAtIndex:i]objectForKey:@"measureSeverity"]]
//                                    andHealthStatusCode:[NSString stringWithFormat:@"%@",[[[[deviceDetails objectForKey:@"response"] objectForKey:@"devices"] objectAtIndex:i]objectForKey:@"healthStatusCode"]]
//                                    andHealthStatusText:[NSString stringWithFormat:@"%@",[[[[deviceDetails objectForKey:@"response"] objectForKey:@"devices"] objectAtIndex:i]objectForKey:@"healthStatusText"]]
//                                   andHealthStatusColor:[NSString stringWithFormat:@"%@",[[[[deviceDetails objectForKey:@"response"] objectForKey:@"devices"] objectAtIndex:i]objectForKey:@"healthStatusColor"]]
//                                     andConnectionState:[NSString stringWithFormat:@"%@",[[[[[deviceDetails objectForKey:@"response"] objectForKey:@"devices"] objectAtIndex:i]objectForKey:@"connecttionState"] objectForKey:@"status"]]];
//        
//        
//        
//        
//        [devices addObject:device];
//    }
    
}

#pragma mark - View Logs

- (NSArray*)viewLogsDetails{

    return viewLogsArr;
}


- (void)viewLog:(NSDictionary*)viewLogDetails{

    viewLogsArr = [NSMutableArray array];

    
    for (int i = 0; i < [[[viewLogDetails objectForKey:@"response"] objectForKey:@"viewLog"] count]; i++) {
        
        ViewLogs *viewLogsDict;
        
        for (int j = 0; j < [[[[[viewLogDetails objectForKey:@"response"] objectForKey:@"viewLog"] objectAtIndex:i] objectForKey:@"userNotified"] count] ; j++) {
            
//            viewLogsDict = [UserNotified ViewLogID:[NSString stringWithFormat:@"%@",[[[[[viewLogDetails objectForKey:@"response"] objectForKey:@"viewLog"] objectAtIndex:i] objectForKey:@"log"] objectForKey:@"logId"]]
//                                                andLocaltime:[NSString stringWithFormat:@"%@",[[[[[viewLogDetails objectForKey:@"response"] objectForKey:@"viewLog"] objectAtIndex:i] objectForKey:@"log"] objectForKey:@"localTime"]]
//                                              andVoyagerDate:[NSString stringWithFormat:@"%@",[[[[[viewLogDetails objectForKey:@"response"] objectForKey:@"viewLog"] objectAtIndex:i] objectForKey:@"log"] objectForKey:@"voyagerDate"]]
//                                              andVoyagerTime:[NSString stringWithFormat:@"%@",[[[[[viewLogDetails objectForKey:@"response"] objectForKey:@"viewLog"] objectAtIndex:i] objectForKey:@"log"] objectForKey:@"voyagerTime"]]
//                                           andLogDescription:[NSString stringWithFormat:@"%@",[[[[[viewLogDetails objectForKey:@"response"] objectForKey:@"viewLog"] objectAtIndex:i] objectForKey:@"log"] objectForKey:@"logDescription"]]
//                                                andAlarmText:[NSString stringWithFormat:@"%@",[[[[[viewLogDetails objectForKey:@"response"] objectForKey:@"viewLog"] objectAtIndex:i] objectForKey:@"log"] objectForKey:@"alarmText"]]
//                                            andSmsEmailLogID:[NSString stringWithFormat:@"%@",[[[[[[viewLogDetails objectForKey:@"response"] objectForKey:@"viewLog"] objectAtIndex:i] objectForKey:@"userNotified"] objectAtIndex:j] objectForKey:@"smsEmailLogId"]]
//                                                 andAlarmLog:nil
//                                                   andUserID:nil
//                                                 andUsername:nil
//                                                andUserEmail:nil
//                                                andUserPhone:nil
//                                                andSmsStatus:nil
//                                              andemailStatus:nil
//                                         andEmailDescription:nil
//                                           andSmsDescription:nil
//                                                  andChecked:nil];
            
            
            viewLogsDict = [UserNotified ViewLogID:[NSString stringWithFormat:@"%@",[[[[[viewLogDetails objectForKey:@"response"] objectForKey:@"viewLog"] objectAtIndex:i] objectForKey:@"log"] objectForKey:@"logId"]]
                                                andLocaltime:[NSString stringWithFormat:@"%@",[[[[[viewLogDetails objectForKey:@"response"] objectForKey:@"viewLog"] objectAtIndex:i] objectForKey:@"log"] objectForKey:@"localTime"]]
                                              andVoyagerDate:[NSString stringWithFormat:@"%@",[[[[[viewLogDetails objectForKey:@"response"] objectForKey:@"viewLog"] objectAtIndex:i] objectForKey:@"log"] objectForKey:@"voyagerDate"]]
                                              andVoyagerTime:[NSString stringWithFormat:@"%@",[[[[[viewLogDetails objectForKey:@"response"] objectForKey:@"viewLog"] objectAtIndex:i] objectForKey:@"log"] objectForKey:@"voyagerTime"]]
                                           andLogDescription:[NSString stringWithFormat:@"%@",[[[[[viewLogDetails objectForKey:@"response"] objectForKey:@"viewLog"] objectAtIndex:i] objectForKey:@"log"] objectForKey:@"logDescription"]]
                                                andAlarmText:[NSString stringWithFormat:@"%@",[[[[[viewLogDetails objectForKey:@"response"] objectForKey:@"viewLog"] objectAtIndex:i] objectForKey:@"log"] objectForKey:@"alarmText"]]
                                            andSmsEmailLogID:[NSString stringWithFormat:@"%@",[[[[[[viewLogDetails objectForKey:@"response"] objectForKey:@"viewLog"] objectAtIndex:i] objectForKey:@"userNotified"] objectAtIndex:j] objectForKey:@"smsEmailLogId"]]
                                                 andAlarmLog:[NSString stringWithFormat:@"%@",[[[[[[viewLogDetails objectForKey:@"response"] objectForKey:@"viewLog"] objectAtIndex:i] objectForKey:@"userNotified"] objectAtIndex:j] objectForKey:@"alarmlogId"]]
                                                   andUserID:[NSString stringWithFormat:@"%@",[[[[[[viewLogDetails objectForKey:@"response"] objectForKey:@"viewLog"] objectAtIndex:i] objectForKey:@"userNotified"] objectAtIndex:j] objectForKey:@"userId"]]
                                                 andUsername:[NSString stringWithFormat:@"%@",[[[[[[viewLogDetails objectForKey:@"response"] objectForKey:@"viewLog"] objectAtIndex:i] objectForKey:@"userNotified"] objectAtIndex:j] objectForKey:@"userName"]]
                                                andUserEmail:[NSString stringWithFormat:@"%@",[[[[[[viewLogDetails objectForKey:@"response"] objectForKey:@"viewLog"] objectAtIndex:i] objectForKey:@"userNotified"] objectAtIndex:j] objectForKey:@"userEmail"]]
                                                andUserPhone:[NSString stringWithFormat:@"%@",[[[[[[viewLogDetails objectForKey:@"response"] objectForKey:@"viewLog"] objectAtIndex:i] objectForKey:@"userNotified"] objectAtIndex:j] objectForKey:@"userPhone"]]
                                                andSmsStatus:[NSString stringWithFormat:@"%@",[[[[[[viewLogDetails objectForKey:@"response"] objectForKey:@"viewLog"] objectAtIndex:i] objectForKey:@"userNotified"] objectAtIndex:j] objectForKey:@"smsStatus"]]
                                              andemailStatus:[NSString stringWithFormat:@"%@",[[[[[[viewLogDetails objectForKey:@"response"] objectForKey:@"viewLog"] objectAtIndex:i] objectForKey:@"userNotified"] objectAtIndex:j] objectForKey:@"emailStatus"]]
                                         andEmailDescription:[NSString stringWithFormat:@"%@",[[[[[[viewLogDetails objectForKey:@"response"] objectForKey:@"viewLog"] objectAtIndex:i] objectForKey:@"userNotified"] objectAtIndex:j] objectForKey:@"emailDescription"]]
                                           andSmsDescription:[NSString stringWithFormat:@"%@",[[[[[[viewLogDetails objectForKey:@"response"] objectForKey:@"viewLog"] objectAtIndex:i] objectForKey:@"userNotified"] objectAtIndex:j] objectForKey:@"smsDescription"]]
                                                  andChecked:[NSString stringWithFormat:@"%@",[[[[[[viewLogDetails objectForKey:@"response"] objectForKey:@"viewLog"] objectAtIndex:i] objectForKey:@"userNotified"] objectAtIndex:j] objectForKey:@"checked"]]];

            
            
        }
        
        [viewLogsArr addObject:viewLogsDict];

        
        
    }
}

#pragma mark - Alarm Log

- (NSArray*)alarmLogs{

    return alarmArr;
}

- (void)alarmLogs:(NSDictionary*)logs{

    NSLog(@"Alarm Log = %@", logs);
    
    
    alarmArr = [NSMutableArray array];
    
    NSMutableArray *reversingData = [NSMutableArray array];
    
    
    if ([[[logs objectForKey:@"response"] objectForKey:@"deviceType"] isEqualToString:@"ultf_silver"] || [[[logs objectForKey:@"response"] objectForKey:@"deviceType"] isEqualToString:@"ultf_gold"]) {
        
        for (int i = 0; i < [[[logs objectForKey:@"response"] objectForKey:@"alarmLog"] count]; i++) {
            
            Devices *devicesPGS = [DevicesCurrentTemperature_PGS alarmDevicesType:[[logs objectForKey:@"response"] objectForKey:@"deviceType"]
                                                                     andFreezerID:[[logs objectForKey:@"response"] objectForKey:@"freezerId"]
                                                                   andFreezerName:[[logs objectForKey:@"response"] objectForKey:@"freezerName"]
                                                                     andCompanyID:[[logs objectForKey:@"response"] objectForKey:@"companyId"]
                                                     andChamberTemperaturesSensor:[[[logs objectForKey:@"response"] objectForKey:@"currentTemperature"] objectForKey:@"chamberTemperatureSensor"]
                                                               andChamberSetPoint:[[[logs objectForKey:@"response"] objectForKey:@"currentTemperature"] objectForKey:@"chamberSetPoint"]
                                                                 andOccuranceTime:[[[[logs objectForKey:@"response"] objectForKey:@"alarmLog"] objectAtIndex:i] objectForKey:@"occuranceTime"]
                                                                     andAlarmCode:[[[[logs objectForKey:@"response"] objectForKey:@"alarmLog"] objectAtIndex:i] objectForKey:@"alarmCode"]
                                                                     andAlarmText:[[[[logs objectForKey:@"response"] objectForKey:@"alarmLog"] objectAtIndex:i] objectForKey:@"alarmText"]
                                                                 andMeasureStatus:[[[[logs objectForKey:@"response"] objectForKey:@"alarmLog"] objectAtIndex:i] objectForKey:@"measureStatus"]
                                                                   andMeasureName:[[[[logs objectForKey:@"response"] objectForKey:@"alarmLog"] objectAtIndex:i] objectForKey:@"measureName"]
                                                            andMeasureDescription:[[[[logs objectForKey:@"response"] objectForKey:@"alarmLog"] objectAtIndex:i] objectForKey:@"measureDescription"]
                                                               andMeasureSeverity:[[[[logs objectForKey:@"response"] objectForKey:@"alarmLog"] objectAtIndex:i]objectForKey:@"measureSeverity"]
                                                                    andCronStatus:[[[[logs objectForKey:@"response"] objectForKey:@"alarmLog"] objectAtIndex:i] objectForKey:@"cronStatus"]];
            
            [reversingData addObject:devicesPGS];
            alarmArr = [[[reversingData reverseObjectEnumerator] allObjects] mutableCopy];
//            [alarmArr addObject:devicesPGS];
            
        }
        
        
        
    }else if ([[[logs objectForKey:@"response"] objectForKey:@"deviceType"] isEqualToString:@"ultf_platinum"]){
        
        
        for (int i = 0; i < [[[logs objectForKey:@"response"] objectForKey:@"alarmLog"] count]; i++) {
            
            Devices *devicesPlatinum = [DevicesCurrentTemperature_Platinum alarmDevicesType:[[logs objectForKey:@"response"] objectForKey:@"deviceType"]
                                                                               andFreezerID:[[logs objectForKey:@"response"] objectForKey:@"freezerId"]
                                                                             andFreezerName:[[logs objectForKey:@"response"] objectForKey:@"freezerName"]
                                                                               andCompanyID:[[logs objectForKey:@"response"] objectForKey:@"companyId"]
                                                               andChamberTemperaturesSensor:[[[logs objectForKey:@"response"] objectForKey:@"currentTemperature"] objectForKey:@"chamberTemperatureSensor"]
                                                                         andChamberSetPoint:[[[logs objectForKey:@"response"] objectForKey:@"currentTemperature"] objectForKey:@"chamberSetPoint"]
                                                                           andOccuranceTime:[[[[logs objectForKey:@"response"] objectForKey:@"alarmLog"] objectAtIndex:i] objectForKey:@"occuranceTime"]
                                                                               andAlarmCode:[[[[logs objectForKey:@"response"] objectForKey:@"alarmLog"] objectAtIndex:i] objectForKey:@"alarmCode"]
                                                                               andAlarmText:[[[[logs objectForKey:@"response"] objectForKey:@"alarmLog"] objectAtIndex:i] objectForKey:@"alarmText"]
                                                                           andMeasureStatus:[[[[logs objectForKey:@"response"] objectForKey:@"alarmLog"] objectAtIndex:i] objectForKey:@"measureStatus"]
                                                                             andMeasureName:[[[[logs objectForKey:@"response"] objectForKey:@"alarmLog"] objectAtIndex:i] objectForKey:@"measureName"]
                                                                      andMeasureDescription:[[[[logs objectForKey:@"response"] objectForKey:@"alarmLog"] objectAtIndex:i] objectForKey:@"measureDescription"]
                                                                         andMeasureSeverity:[[[[logs objectForKey:@"response"] objectForKey:@"alarmLog"] objectAtIndex:i]objectForKey:@"measureSeverity"]
                                                                              andCronStatus:[[[[logs objectForKey:@"response"] objectForKey:@"alarmLog"] objectAtIndex:i] objectForKey:@"cronStatus"]];
            
            
//            [alarmArr addObject:devicesPlatinum];
            [reversingData addObject:devicesPlatinum];
            alarmArr = [[[reversingData reverseObjectEnumerator] allObjects] mutableCopy];
            
        }
        
        
        
    }else if ([[[logs objectForKey:@"response"] objectForKey:@"deviceType"] isEqualToString:@"co2_incubator"]){
        
        for (int i = 0; i < [[[logs objectForKey:@"response"] objectForKey:@"alarmLog"] count]; i++) {
            
            Devices *devicesIncubator = [DevicesCurrentTemperature_CO2Incubator alarmDevicesType:[[logs objectForKey:@"response"] objectForKey:@"deviceType"]
                                                                                    andFreezerID:[[logs objectForKey:@"response"] objectForKey:@"freezerId"]
                                                                                  andFreezerName:[[logs objectForKey:@"response"] objectForKey:@"freezerName"]
                                                                                    andCompanyID:[[logs objectForKey:@"response"] objectForKey:@"companyId"]
                                                                    andChamberTemperaturesSensor:[[[logs objectForKey:@"response"] objectForKey:@"currentTemperature"] objectForKey:@"chamberTemperatureSensor"]
                                                                              andChamberSetPoint:[[[logs objectForKey:@"response"] objectForKey:@"currentTemperature"] objectForKey:@"chamberSetPoint"]
                                                                                andOccuranceTime:[[[[logs objectForKey:@"response"] objectForKey:@"alarmLog"] objectAtIndex:i] objectForKey:@"occuranceTime"]
                                                                                    andAlarmCode:[[[[logs objectForKey:@"response"] objectForKey:@"alarmLog"] objectAtIndex:i] objectForKey:@"alarmCode"]
                                                                                    andAlarmText:[[[[logs objectForKey:@"response"] objectForKey:@"alarmLog"] objectAtIndex:i] objectForKey:@"alarmText"]
                                                                                andMeasureStatus:[[[[logs objectForKey:@"response"] objectForKey:@"alarmLog"] objectAtIndex:i] objectForKey:@"measureStatus"]
                                                                                  andMeasureName:[[[[logs objectForKey:@"response"] objectForKey:@"alarmLog"] objectAtIndex:i] objectForKey:@"measureName"]
                                                                           andMeasureDescription:[[[[logs objectForKey:@"response"] objectForKey:@"alarmLog"] objectAtIndex:i] objectForKey:@"measureDescription"]
                                                                              andMeasureSeverity:[[[[logs objectForKey:@"response"] objectForKey:@"alarmLog"] objectAtIndex:i]objectForKey:@"measureSeverity"]
                                                                                   andCronStatus:[[[[logs objectForKey:@"response"] objectForKey:@"alarmLog"] objectAtIndex:i] objectForKey:@"cronStatus"]];
            
            
//            [alarmArr addObject:devicesIncubator];
            [reversingData addObject:devicesIncubator];
            alarmArr = [[[reversingData reverseObjectEnumerator] allObjects] mutableCopy];
            
        }
        
        
        
        
    }else if ([[[logs objectForKey:@"response"] objectForKey:@"deviceType"] isEqualToString:@"ecs-g2"]){
        
        
        for (int i = 0; i < [[[logs objectForKey:@"response"] objectForKey:@"alarmLog"] count]; i++) {
            
            Devices *devicesEGSG2 = [DevicesCurrentTemperature_EGS_G2 alarmDevicesType:[[logs objectForKey:@"response"] objectForKey:@"deviceType"]
                                                                         andFreezerID:[[logs objectForKey:@"response"] objectForKey:@"freezerId"]
                                                                       andFreezerName:[[logs objectForKey:@"response"] objectForKey:@"freezerName"]
                                                                         andCompanyID:[[logs objectForKey:@"response"] objectForKey:@"companyId"]
                                                         andChamberTemperaturesSensor:[[[logs objectForKey:@"response"] objectForKey:@"currentTemperature"] objectForKey:@"chamberTemperatureSensor"]
                                                                   andChamberSetPoint:[[[logs objectForKey:@"response"] objectForKey:@"currentTemperature"] objectForKey:@"chamberSetPoint"]
                                                                     andOccuranceTime:[[[[logs objectForKey:@"response"] objectForKey:@"alarmLog"] objectAtIndex:i] objectForKey:@"occuranceTime"]
                                                                         andAlarmCode:[[[[logs objectForKey:@"response"] objectForKey:@"alarmLog"] objectAtIndex:i] objectForKey:@"alarmCode"]
                                                                         andAlarmText:[[[[logs objectForKey:@"response"] objectForKey:@"alarmLog"] objectAtIndex:i] objectForKey:@"alarmText"]
                                                                     andMeasureStatus:[[[[logs objectForKey:@"response"] objectForKey:@"alarmLog"] objectAtIndex:i] objectForKey:@"measureStatus"]
                                                                       andMeasureName:[[[[logs objectForKey:@"response"] objectForKey:@"alarmLog"] objectAtIndex:i] objectForKey:@"measureName"]
                                                                andMeasureDescription:[[[[logs objectForKey:@"response"] objectForKey:@"alarmLog"] objectAtIndex:i] objectForKey:@"measureDescription"]
                                                                   andMeasureSeverity:[[[[logs objectForKey:@"response"] objectForKey:@"alarmLog"] objectAtIndex:i]objectForKey:@"measureSeverity"]
                                                                        andCronStatus:[[[[logs objectForKey:@"response"] objectForKey:@"alarmLog"] objectAtIndex:i] objectForKey:@"cronStatus"]];
            
            
//            [alarmArr addObject:devicesEGSG2];
            [reversingData addObject:devicesEGSG2];
            alarmArr = [[[reversingData reverseObjectEnumerator] allObjects] mutableCopy];
            
        }
        
        
    }else if ([[[logs objectForKey:@"response"] objectForKey:@"deviceType"] isEqualToString:@"ofa"] || [[[logs objectForKey:@"response"] objectForKey:@"deviceType"] isEqualToString:@"ifa"] || [[[logs objectForKey:@"response"] objectForKey:@"deviceType"] isEqualToString:@"ifc"] || [[[logs objectForKey:@"response"] objectForKey:@"deviceType"] isEqualToString:@"ina"]){
        
        
        for (int i = 0; i < [[[logs objectForKey:@"response"] objectForKey:@"alarmLog"] count]; i++) {
            
            Devices *devicesOFAIFAIFCINA = [DevicesCurrentTemperature_OFA_IFA_IFC_INA alarmDevicesType:[[logs objectForKey:@"response"] objectForKey:@"deviceType"]
                                                                                         andFreezerID:[[logs objectForKey:@"response"] objectForKey:@"freezerId"]
                                                                                       andFreezerName:[[logs objectForKey:@"response"] objectForKey:@"freezerName"]
                                                                                         andCompanyID:[[logs objectForKey:@"response"] objectForKey:@"companyId"]
                                                                         andChamberTemperaturesSensor:[[[logs objectForKey:@"response"] objectForKey:@"currentTemperature"] objectForKey:@"chamberTemperatureSensor"]
                                                                                   andChamberSetPoint:[[[logs objectForKey:@"response"] objectForKey:@"currentTemperature"] objectForKey:@"chamberSetPoint"]
                                                                                     andOccuranceTime:[[[[logs objectForKey:@"response"] objectForKey:@"alarmLog"] objectAtIndex:i] objectForKey:@"occuranceTime"]
                                                                                         andAlarmCode:[[[[logs objectForKey:@"response"] objectForKey:@"alarmLog"] objectAtIndex:i] objectForKey:@"alarmCode"]
                                                                                         andAlarmText:[[[[logs objectForKey:@"response"] objectForKey:@"alarmLog"] objectAtIndex:i] objectForKey:@"alarmText"]
                                                                                     andMeasureStatus:[[[[logs objectForKey:@"response"] objectForKey:@"alarmLog"] objectAtIndex:i] objectForKey:@"measureStatus"]
                                                                                       andMeasureName:[[[[logs objectForKey:@"response"] objectForKey:@"alarmLog"] objectAtIndex:i] objectForKey:@"measureName"]
                                                                                andMeasureDescription:[[[[logs objectForKey:@"response"] objectForKey:@"alarmLog"] objectAtIndex:i] objectForKey:@"measureDescription"]
                                                                                   andMeasureSeverity:[[[[logs objectForKey:@"response"] objectForKey:@"alarmLog"] objectAtIndex:i]objectForKey:@"measureSeverity"]
                                                                                        andCronStatus:[[[[logs objectForKey:@"response"] objectForKey:@"alarmLog"] objectAtIndex:i] objectForKey:@"cronStatus"]];
            
            
//            [alarmArr addObject:devicesOFAIFAIFCINA];
            [reversingData addObject:devicesOFAIFAIFCINA];
            alarmArr = [[[reversingData reverseObjectEnumerator] allObjects] mutableCopy];
            
        }
        
        
    }

}

#pragma mark - Event Log

- (NSArray*)eventLogs{
    
    return eventArr;
}

- (void)eventLogs:(NSDictionary*)logs{
    
    NSLog(@"Event Log = %@", logs);
    
    eventArr = [NSMutableArray array];
    NSMutableArray *reversingData = [NSMutableArray array];
    
    if ([[[logs objectForKey:@"response"] objectForKey:@"deviceType"] isEqualToString:@"ultf_silver"] || [[[logs objectForKey:@"response"] objectForKey:@"deviceType"] isEqualToString:@"ultf_gold"]) {
        
        for (int i = 0; i < [[[logs objectForKey:@"response"] objectForKey:@"eventLog"] count]; i++) {
            
                Devices *devicesPGS = [DevicesCurrentTemperature_PGS eventDeviceType:[[logs objectForKey:@"response"] objectForKey:@"deviceType"]
                                                                     andFreezerID:[[logs objectForKey:@"response"] objectForKey:@"freezerID"]
                                                                   andFreezerName:[[logs objectForKey:@"response"] objectForKey:@"freezerName"]
                                                                     andCompanyID:[[logs objectForKey:@"response"] objectForKey:@"companyId"]
                                                      andChamberTemperatureSensor:[[[logs objectForKey:@"response"] objectForKey:@"currentTemperature"] objectForKey:@"chamberTemperatureSensor"]
                                                               andChamberSetPoint:[[[logs objectForKey:@"response"] objectForKey:@"currentTemperature"] objectForKey:@"chamberSetPoint"]
                                                                 andOccuranceTime:[[[[logs objectForKey:@"response"] objectForKey:@"eventLog"] objectAtIndex:i] objectForKey:@"occuranceTime"]
                                                                     andEventCode:[[[[logs objectForKey:@"response"] objectForKey:@"eventLog"] objectAtIndex:i] objectForKey:@"eventCode"]];
            
            
//            [eventArr addObject:devicesPGS];
            [reversingData addObject:devicesPGS];
            eventArr = [[[reversingData reverseObjectEnumerator] allObjects] mutableCopy];
            
        }

            
        
    }else if ([[[logs objectForKey:@"response"] objectForKey:@"deviceType"] isEqualToString:@"ultf_platinum"]){
        
        
        for (int i = 0; i < [[[logs objectForKey:@"response"] objectForKey:@"eventLog"] count]; i++) {
            
            Devices *devicesPlatinum = [DevicesCurrentTemperature_Platinum eventDeviceType:[[logs objectForKey:@"response"] objectForKey:@"deviceType"]
                                                                    andFreezerID:[[logs objectForKey:@"response"] objectForKey:@"freezerID"]
                                                                  andFreezerName:[[logs objectForKey:@"response"] objectForKey:@"freezerName"]
                                                                    andCompanyID:[[logs objectForKey:@"response"] objectForKey:@"companyId"]
                                                     andChamberTemperatureSensor:[[[logs objectForKey:@"response"] objectForKey:@"currentTemperature"] objectForKey:@"chamberTemperatureSensor"]
                                                              andChamberSetPoint:[[[logs objectForKey:@"response"] objectForKey:@"currentTemperature"] objectForKey:@"chamberSetPoint"]
                                                                andOccuranceTime:[[[[logs objectForKey:@"response"] objectForKey:@"eventLog"] objectAtIndex:i] objectForKey:@"occuranceTime"]
                                                                    andEventCode:[[[[logs objectForKey:@"response"] objectForKey:@"eventLog"] objectAtIndex:i] objectForKey:@"eventCode"]];
            
            
//            [eventArr addObject:devicesPlatinum];
            [reversingData addObject:devicesPlatinum];
            eventArr = [[[reversingData reverseObjectEnumerator] allObjects] mutableCopy];
            
        }

        
        
    }else if ([[[logs objectForKey:@"response"] objectForKey:@"deviceType"] isEqualToString:@"co2_incubator"]){
        
        for (int i = 0; i < [[[logs objectForKey:@"response"] objectForKey:@"eventLog"] count]; i++) {
            
            Devices *devicesIncubator = [DevicesCurrentTemperature_CO2Incubator eventDeviceType:[[logs objectForKey:@"response"] objectForKey:@"deviceType"]
                                                                    andFreezerID:[[logs objectForKey:@"response"] objectForKey:@"freezerID"]
                                                                  andFreezerName:[[logs objectForKey:@"response"] objectForKey:@"freezerName"]
                                                                    andCompanyID:[[logs objectForKey:@"response"] objectForKey:@"companyId"]
                                                     andChamberTemperatureSensor:[[[logs objectForKey:@"response"] objectForKey:@"currentTemperature"] objectForKey:@"chamberTemperatureSensor"]
                                                              andChamberSetPoint:[[[logs objectForKey:@"response"] objectForKey:@"currentTemperature"] objectForKey:@"chamberSetPoint"]
                                                                andOccuranceTime:[[[[logs objectForKey:@"response"] objectForKey:@"eventLog"] objectAtIndex:i] objectForKey:@"occuranceTime"]
                                                                    andEventCode:[[[[logs objectForKey:@"response"] objectForKey:@"eventLog"] objectAtIndex:i] objectForKey:@"eventCode"]];
            
            
//            [eventArr addObject:devicesIncubator];
            [reversingData addObject:devicesIncubator];
            eventArr = [[[reversingData reverseObjectEnumerator] allObjects] mutableCopy];
            
        }

        
        
        
    }else if ([[[logs objectForKey:@"response"] objectForKey:@"deviceType"] isEqualToString:@"ecs-g2"]){
        
        
        for (int i = 0; i < [[[logs objectForKey:@"response"] objectForKey:@"eventLog"] count]; i++) {
            
            Devices *devicesEGSG2 = [DevicesCurrentTemperature_EGS_G2 eventDeviceType:[[logs objectForKey:@"response"] objectForKey:@"deviceType"]
                                                                    andFreezerID:[[logs objectForKey:@"response"] objectForKey:@"freezerID"]
                                                                  andFreezerName:[[logs objectForKey:@"response"] objectForKey:@"freezerName"]
                                                                    andCompanyID:[[logs objectForKey:@"response"] objectForKey:@"companyId"]
                                                     andChamberTemperatureSensor:[[[logs objectForKey:@"response"] objectForKey:@"currentTemperature"] objectForKey:@"chamberTemperatureSensor"]
                                                              andChamberSetPoint:[[[logs objectForKey:@"response"] objectForKey:@"currentTemperature"] objectForKey:@"chamberSetPoint"]
                                                                andOccuranceTime:[[[[logs objectForKey:@"response"] objectForKey:@"eventLog"] objectAtIndex:i] objectForKey:@"occuranceTime"]
                                                                    andEventCode:[[[[logs objectForKey:@"response"] objectForKey:@"eventLog"] objectAtIndex:i] objectForKey:@"eventCode"]];
            
            
//            [eventArr addObject:devicesEGSG2];
            [reversingData addObject:devicesEGSG2];
            eventArr = [[[reversingData reverseObjectEnumerator] allObjects] mutableCopy];
            
        }

        
    }else if ([[[logs objectForKey:@"response"] objectForKey:@"deviceType"] isEqualToString:@"ofa"] || [[[logs objectForKey:@"response"] objectForKey:@"deviceType"] isEqualToString:@"ifa"] || [[[logs objectForKey:@"response"] objectForKey:@"deviceType"] isEqualToString:@"ifc"] || [[[logs objectForKey:@"response"] objectForKey:@"deviceType"] isEqualToString:@"ina"]){
     
        
        for (int i = 0; i < [[[logs objectForKey:@"response"] objectForKey:@"eventLog"] count]; i++) {
            
            Devices *devicesOFAIFAIFCINA = [DevicesCurrentTemperature_OFA_IFA_IFC_INA eventDeviceType:[[logs objectForKey:@"response"] objectForKey:@"deviceType"]
                                                                    andFreezerID:[[logs objectForKey:@"response"] objectForKey:@"freezerID"]
                                                                  andFreezerName:[[logs objectForKey:@"response"] objectForKey:@"freezerName"]
                                                                    andCompanyID:[[logs objectForKey:@"response"] objectForKey:@"companyId"]
                                                     andChamberTemperatureSensor:[[[logs objectForKey:@"response"] objectForKey:@"currentTemperature"] objectForKey:@"chamberTemperatureSensor"]
                                                              andChamberSetPoint:[[[logs objectForKey:@"response"] objectForKey:@"currentTemperature"] objectForKey:@"chamberSetPoint"]
                                                                andOccuranceTime:[[[[logs objectForKey:@"response"] objectForKey:@"eventLog"] objectAtIndex:i] objectForKey:@"occuranceTime"]
                                                                    andEventCode:[[[[logs objectForKey:@"response"] objectForKey:@"eventLog"] objectAtIndex:i] objectForKey:@"eventCode"]];
            
            
//            [eventArr addObject:devicesOFAIFAIFCINA];
            [reversingData addObject:devicesOFAIFAIFCINA];
            eventArr = [[[reversingData reverseObjectEnumerator] allObjects] mutableCopy];
            
        }

        
    }

}

- (NSString*)equipmentType{

    return type;
}

- (void)getEquipmentType:(NSString*)equipmentType{

    type = equipmentType;
}
#pragma mark - Sensor Log

- (NSArray*)sensorLogs{
    
    return sensorArr;
}

- (void)sensorLogs:(NSDictionary*)logs{
    
    NSLog(@"Sensor Log = %@", logs);
    
    sensorArr = [NSMutableArray array];
    
    NSMutableArray *reversingData = [NSMutableArray array];
    
    if ([[[logs objectForKey:@"response"] objectForKey:@"deviceType"] isEqualToString:@"ultf_silver"] || [[[logs objectForKey:@"response"] objectForKey:@"deviceType"] isEqualToString:@"ultf_gold"]) {
        
        for (int i = 0; i < [[[logs objectForKey:@"response"] objectForKey:@"sensorLog"] count]; i++) {
            
            Devices *devicePgs = [DevicesCurrentTemperature_PGS devicesType:[[logs objectForKey:@"response"] objectForKey:@"deviceType"]
                                                               andFreezerID:[[logs objectForKey:@"response"] objectForKey:@"freezerId"]
                                                andChamberTemperatureSensor:[[[[logs objectForKey:@"response"] objectForKey:@"sensorLog"] objectAtIndex:i] objectForKey:@"chamberTemperatureSensor"]
                                                         andChamberSetPoint:[[[[logs objectForKey:@"response"] objectForKey:@"sensorLog"] objectAtIndex:i] objectForKey:@"chamberSetPoint"]
                                                           andOccuranceTime:[[[[logs objectForKey:@"response"] objectForKey:@"sensorLog"] objectAtIndex:i] objectForKey:@"occuranceTime"]
                                                    andhighTemperatureLimit:[[[[logs objectForKey:@"response"] objectForKey:@"sensorLog"] objectAtIndex:i] objectForKey:@"highTemperatureLimit"]
                                                     andlowTemperatureLimit:[[[[logs objectForKey:@"response"] objectForKey:@"sensorLog"] objectAtIndex:i] objectForKey:@"lowTemperatureLimit"]
                                                        andNtcAmbientSensor:[[[[logs objectForKey:@"response"] objectForKey:@"sensorLog"] objectAtIndex:i] objectForKey:@"ntcAmbientSensor"]
                                                      andntcCondenserSensor:[[[[logs objectForKey:@"response"] objectForKey:@"sensorLog"] objectAtIndex:i] objectForKey:@"ntcCondenserSensor"]
                                                       andNtcHeatExchanger1:[[[[logs objectForKey:@"response"] objectForKey:@"sensorLog"] objectAtIndex:i] objectForKey:@"ntcHeatExchanger1"]
                                                       andNtcHeatExchanger2:[[[[logs objectForKey:@"response"] objectForKey:@"sensorLog"] objectAtIndex:i] objectForKey:@"ntcHeatExchanger2"]
                                                               andAcVoltage:[[[[logs objectForKey:@"response"] objectForKey:@"sensorLog"] objectAtIndex:i] objectForKey:@"acVoltage"]];
            
            
            
            [reversingData addObject:devicePgs];
            sensorArr = [[[reversingData reverseObjectEnumerator] allObjects] mutableCopy];
            //[sensorArr addObject:devicePgs];
            
        }
        
    }else if ([[[logs objectForKey:@"response"] objectForKey:@"deviceType"] isEqualToString:@"ultf_platinum"]){
        
        for (int i = 0; i < [[[logs objectForKey:@"response"] objectForKey:@"sensorLog"] count]; i++) {
            
        Devices *devicesPlatinum = [DevicesCurrentTemperature_Platinum devicesType:[[logs objectForKey:@"response"] objectForKey:@"deviceType"]
                                                                      andFreezerID:[[logs objectForKey:@"response"] objectForKey:@"freezerId"]
                                                       andChamberTemperatureSensor:[[[[logs objectForKey:@"response"] objectForKey:@"sensorLog"] objectAtIndex:i] objectForKey:@"chamberTemperatureSensor"]
                                                                andChamberSetPoint:[[[[logs objectForKey:@"response"] objectForKey:@"sensorLog"] objectAtIndex:i] objectForKey:@"chamberSetPoint"]
                                                                  andOccuranceTime:[[[[logs objectForKey:@"response"] objectForKey:@"sensorLog"] objectAtIndex:i] objectForKey:@"occuranceTime"]
                                                           andHighTemperatureLimit:[[[[logs objectForKey:@"response"] objectForKey:@"sensorLog"] objectAtIndex:i] objectForKey:@"highTemperatureLimit"]
                                                            andlowTemperatureLimit:[[[[logs objectForKey:@"response"] objectForKey:@"sensorLog"] objectAtIndex:i] objectForKey:@"lowTemperatureLimit"]
                                                                  andAmbientSensor:[[[[logs objectForKey:@"response"] objectForKey:@"sensorLog"] objectAtIndex:i] objectForKey:@"ambientSensor"]
                                                          andCondenserOutletSensor:[[[[logs objectForKey:@"response"] objectForKey:@"sensorLog"] objectAtIndex:i] objectForKey:@"condenserOutletSensor"]
                                                        andheatExchangerTempSensor:[[[[logs objectForKey:@"response"] objectForKey:@"sensorLog"] objectAtIndex:i] objectForKey:@"heatexchangerTempSensor"]
                                                                   andevapInSensor:[[[[logs objectForKey:@"response"] objectForKey:@"sensorLog"] objectAtIndex:i] objectForKey:@"evapInSensor"]
                                                                  andEvapOutSensor:[[[[logs objectForKey:@"response"] objectForKey:@"sensorLog"] objectAtIndex:i] objectForKey:@"evapOutSensor"]
                                                                 andBatteryVoltage:[[[[logs objectForKey:@"response"] objectForKey:@"sensorLog"] objectAtIndex:i] objectForKey:@"batteryVoltage"]
                                                                      andAcVoltage:[[[[logs objectForKey:@"response"] objectForKey:@"sensorLog"] objectAtIndex:i] objectForKey:@"acVoltage"]
                                                                      andHighStage:[[[[logs objectForKey:@"response"] objectForKey:@"sensorLog"] objectAtIndex:i] objectForKey:@"highStage"]];
            [reversingData addObject:devicesPlatinum];
            sensorArr = [[[reversingData reverseObjectEnumerator] allObjects] mutableCopy];
//            [sensorArr addObject:devicesPlatinum];
        }
    
    
    }else if ([[[logs objectForKey:@"response"] objectForKey:@"deviceType"] isEqualToString:@"co2_incubator"]){
        
        for (int i = 0; i < [[[logs objectForKey:@"response"] objectForKey:@"sensorLog"] count]; i++) {
            
            
            Devices *devicesCo2Incubator = [DevicesCurrentTemperature_CO2Incubator
                                            devicesWithFreezerID:[[logs objectForKey:@"response"] objectForKey:@"freezerId"]
                                            andTemperatureSetPoint:[[[[logs objectForKey:@"response"] objectForKey:@"sensorLog"] objectAtIndex:i] objectForKey:@"temperatureSetPoint"]
                                            andCo2SetPoint:[[[[logs objectForKey:@"response"] objectForKey:@"sensorLog"] objectAtIndex:i] objectForKey:@"co2SetPoint"]
                                            andO2SetPoint:[[[[logs objectForKey:@"response"] objectForKey:@"sensorLog"] objectAtIndex:i] objectForKey:@"o2SetPoint"]
                                            andTemperatureSensorStr:[[[[logs objectForKey:@"response"] objectForKey:@"sensorLog"] objectAtIndex:i] objectForKey:@"temperatureSensor"]
                                            andCo2Sensor:[[[[logs objectForKey:@"response"] objectForKey:@"sensorLog"] objectAtIndex:i] objectForKey:@"co2Sensor"]
                                            andO2Sensor:[[[[logs objectForKey:@"response"] objectForKey:@"sensorLog"] objectAtIndex:i] objectForKey:@"o2Sensor"]
                                            andRhSensor:[[[[logs objectForKey:@"response"] objectForKey:@"sensorLog"] objectAtIndex:i] objectForKey:@"rhSensor"]
                                            andDeviceType:[[logs objectForKey:@"response"] objectForKey:@"deviceType"]
                                            andOccuranceTime:[[[[logs objectForKey:@"response"] objectForKey:@"sensorLog"] objectAtIndex:i] objectForKey:@"occuranceTime"]
                                            andHighTemperatureLimit:[[[[logs objectForKey:@"response"] objectForKey:@"sensorLog"] objectAtIndex:i] objectForKey:@"highTemperatureLimit"]
                                            andLowTemperatureLimit:[[[[logs objectForKey:@"response"] objectForKey:@"sensorLog"] objectAtIndex:i] objectForKey:@"lowTemperatureLimit"]
                                            andHighCo2Limit:[[[[logs objectForKey:@"response"] objectForKey:@"sensorLog"] objectAtIndex:i] objectForKey:@"highCo2Limit"]
                                            andLowCo2Limit:[[[[logs objectForKey:@"response"] objectForKey:@"sensorLog"] objectAtIndex:i] objectForKey:@"lowCo2Limit"]
                                            andHighO2Limit:[[[[logs objectForKey:@"response"] objectForKey:@"sensorLog"] objectAtIndex:i] objectForKey:@"highO2Limit"]
                                            andLowO2Limit:[[[[logs objectForKey:@"response"] objectForKey:@"sensorLog"] objectAtIndex:i] objectForKey:@"lowO2Limit"]
                                            andLowRhLimit:[[[[logs objectForKey:@"response"] objectForKey:@"sensorLog"] objectAtIndex:i] objectForKey:@"lowRhLimit"]];
        
        
            [reversingData addObject:devicesCo2Incubator];
            sensorArr = [[[reversingData reverseObjectEnumerator] allObjects] mutableCopy];
//            [sensorArr addObject:devicesCo2Incubator];
        }
    
    
    }else if ([[[logs objectForKey:@"response"] objectForKey:@"deviceType"] isEqualToString:@"ecs-g2"]){
        
        for (int i = 0; i < [[[logs objectForKey:@"response"] objectForKey:@"sensorLog"] count]; i++) {
        
            Devices *devicesECSG2 = [DevicesCurrentTemperature_EGS_G2
                                     devicesWithFreezerID:[[logs objectForKey:@"response"] objectForKey:@"freezerId"]
                                     andInFlowSensor:[[[[logs objectForKey:@"response"] objectForKey:@"sensorLog"] objectAtIndex:i] objectForKey:@"inflowSensor"]
                                     andDownFlowSensor:[[[[logs objectForKey:@"response"] objectForKey:@"sensorLog"] objectAtIndex:i] objectForKey:@"downflowSensor"]
                                     andDeviceType:[[logs objectForKey:@"response"] objectForKey:@"deviceType"]
                                     andOccuranceTime:[[[[logs objectForKey:@"response"] objectForKey:@"sensorLog"] objectAtIndex:i] objectForKey:@"occuranceTime"]
                                     andLowInFlowLimit:[[[[logs objectForKey:@"response"] objectForKey:@"sensorLog"] objectAtIndex:i] objectForKey:@"lowInflowLimit"]
                                     andHighDownFlowLimit:[[[[logs objectForKey:@"response"] objectForKey:@"sensorLog"] objectAtIndex:i] objectForKey:@"highDownflowLimit"]
                                     andLowDownFlowLimit:[[[[logs objectForKey:@"response"] objectForKey:@"sensorLog"] objectAtIndex:i] objectForKey:@"lowDownflowLimit"]
                                     andHighTemperatureLimit:[[[[logs objectForKey:@"response"] objectForKey:@"sensorLog"] objectAtIndex:i] objectForKey:@"highTemperatureLimit"]
                                     andLowTemperatureLimit:[[[[logs objectForKey:@"response"] objectForKey:@"sensorLog"] objectAtIndex:i] objectForKey:@"lowTemperatureLimit"]
                                     andHighDcVoltageLimit:[[[[logs objectForKey:@"response"] objectForKey:@"sensorLog"] objectAtIndex:i] objectForKey:@"highDcVoltageLimit"]
                                     andlowDcVoltageLimit:[[[[logs objectForKey:@"response"] objectForKey:@"sensorLog"] objectAtIndex:i] objectForKey:@"lowDcVoltageLimit"]
                                     andTemperatureSensor:[[[[logs objectForKey:@"response"] objectForKey:@"sensorLog"] objectAtIndex:i] objectForKey:@"temperatureSensor"]
                                     andDcVoltage:[[[[logs objectForKey:@"response"] objectForKey:@"sensorLog"] objectAtIndex:i] objectForKey:@"dcVoltage"]];
            
            
            
            [reversingData addObject:devicesECSG2];
            sensorArr = [[[reversingData reverseObjectEnumerator] allObjects] mutableCopy];
//            [sensorArr addObject:devicesECSG2];
        
        }
    
    
    
    }else if ([[[logs objectForKey:@"response"] objectForKey:@"deviceType"] isEqualToString:@"ofa"] || [[[logs objectForKey:@"response"] objectForKey:@"deviceType"] isEqualToString:@"ifa"] || [[[logs objectForKey:@"response"] objectForKey:@"deviceType"] isEqualToString:@"ifc"] || [[[logs objectForKey:@"response"] objectForKey:@"deviceType"] isEqualToString:@"ina"]){
    
        for (int i = 0; i < [[[logs objectForKey:@"response"] objectForKey:@"sensorLog"] count]; i++) {
        
            Devices *devicesOFAIFAIFCINA = [DevicesCurrentTemperature_OFA_IFA_IFC_INA
                                            devicesWithFreezerID:[[logs objectForKey:@"response"] objectForKey:@"freezerId"]
                                            andChamberTemperatureSensor:[[[[logs objectForKey:@"response"] objectForKey:@"sensorLog"] objectAtIndex:i] objectForKey:@"chamberTemperatureSensor"]
                                            andChamberSetPoint:[[[[logs objectForKey:@"response"] objectForKey:@"sensorLog"] objectAtIndex:i] objectForKey:@"chamberSetPoint"]
                                            andDeviceType:[[logs objectForKey:@"response"] objectForKey:@"deviceType"]
                                            andOccuranceTime:[[[[logs objectForKey:@"response"] objectForKey:@"sensorLog"] objectAtIndex:i] objectForKey:@"occuranceTime"]
                                            andHighTemperatureLimit:[[[[logs objectForKey:@"response"] objectForKey:@"sensorLog"] objectAtIndex:i] objectForKey:@"highTemperatureLimit"]
                                            andLowTemperatureLimit:[[[[logs objectForKey:@"response"] objectForKey:@"sensorLog"] objectAtIndex:i] objectForKey:@"lowTemperatureLimit"]];
            
//            [sensorArr addObject:devicesOFAIFAIFCINA];
            [reversingData addObject:devicesOFAIFAIFCINA];
            sensorArr = [[[reversingData reverseObjectEnumerator] allObjects] mutableCopy];
        
        }
    
    }
    
}

- (NSString*)setPoint{
    
    
    
    return setPointStr;
}

- (void)getSetPoint:(NSString*)dataSetPoint{
    
    setPointStr = dataSetPoint;
}

#pragma mark - Get Domain ID

- (NSString*)domainID{

    return domainIDStr;
}

#pragma mark - Empty Data

- (void)emptyData{

    user = nil;
    companies = nil;
    devices = nil;
    viewLogsArr = nil;
    domainIDStr = nil;
    alarmArr = nil;
    eventArr = nil;
    sensorArr = nil;
    
    NSLog(@"%@ %@ %@ %@ %@ %@ %@ %@", user, companies, devices, viewLogsArr, domainIDStr, alarmArr, eventArr, sensorArr);
   

}

- (void)getDomainID:(NSString*)domainID{

    domainIDStr = domainID;
}

- (NSString*)freezerID{

    return freezerIDStr;
}
- (void)getFreezerID:(NSString*)freezerID{

    freezerIDStr = freezerID;
}

#pragma mark - Date Convertion

- (NSDate *)convertLocaltoGMT:(NSString *)localDateStr
{
    NSDateFormatter * formatter = [[NSDateFormatter alloc] init];
    [formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
    
    NSDate *localDate = [formatter dateFromString: localDateStr];
    NSTimeInterval timeZoneOffset = [[NSTimeZone defaultTimeZone] secondsFromGMT]; // You could also use the systemTimeZone method
    NSTimeInterval gmtTimeInterval = [localDate timeIntervalSinceReferenceDate] - timeZoneOffset;
    NSDate *gmtDate = [NSDate dateWithTimeIntervalSinceReferenceDate:gmtTimeInterval];
    
    return gmtDate;
}

#pragma mark - SingleTon

+ (ParserClass *)sharedItems
{
    if (sharedItem == nil) {
        sharedItem = [[super allocWithZone:NULL]init];
    }
    return  sharedItem;
}
- (id)init{
    if ((self = [super init])) {
        
    }
    return self;
}
+ (id)allocWithZone:(NSZone *)zone{
    return  [self sharedItems];
}
- (id)copyWithZone:(NSZone *)zone{
    return self;
}


@end
